package com.dsjy.yf.address.controller;

import com.dsjy.yf.address.annotation.FocusAnnotation;
import com.dsjy.yf.address.config.base.BizException;
import com.dsjy.yf.address.config.base.CommonEnum;
import com.dsjy.yf.address.entity.query.AdminDeleteQuery;
import com.dsjy.yf.address.entity.query.PageSearchQuery;
import com.dsjy.yf.address.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author whj
 * @version 1.0
 * @date 2021-03-10 9:51
 */
@RestController
@FocusAnnotation
@RequestMapping("/admin/backstage/")
@PreAuthorize("hasRole('ADMIN')")
@CrossOrigin(origins = "*", originPatterns = "true")
public class BackstageAdminController {
    @Autowired
    private CommonService commonService;

    @PostMapping("/search/page")
    public Object searchPageByAdmin(@RequestBody PageSearchQuery pageSearchQuery) {
        if (pageSearchQuery.isNotNull()) {
            return commonService.searchWithPage(pageSearchQuery, true);
        } else {
            throw new BizException(CommonEnum.PARAM_ERROR);
        }
    }

    @PostMapping("/delete")
    public Object deleteByAdmin(@RequestBody AdminDeleteQuery query) {
        return commonService.deleteById(query);
    }
}
